Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix trial end check #5772

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

fix trial end check #5772

wants to merge 4 commits into from

Conversation

pjain1
Copy link
Member

@pjain1 pjain1 commented Sep 24, 2024

on-trial issue type is marked as processed after sending trial ending soon email so its not checked in trial end worker. Fetching all orgs that have on-trial issue irrespective of processed or not and deleting the issue and raising trial ended issue in trial end check job.

@@ -89,7 +89,7 @@ func (w *TrialEndCheckWorker) Work(ctx context.Context, job *river.Job[TrialEndC
}

func (w *TrialEndCheckWorker) trialEndCheck(ctx context.Context) error {
onTrialOrgs, err := w.admin.DB.FindBillingIssueByTypeNotOverdueProcessed(ctx, database.BillingIssueTypeOnTrial)
onTrialOrgs, err := w.admin.DB.FindBillingIssueByType(ctx, database.BillingIssueTypeOnTrial)
Copy link
Collaborator

@AdityaHegde AdityaHegde Sep 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be selecting too many rows. One way to avoid is to use something like next_check_time. Index on it and always fetch next_check_time < now and type=....

  1. Set it to now + trial_period - ending_soon_period during creation initially.
  2. In TrialEndingSoonWorker after success set it to next_check_time += ending_soon_period.
  3. Here in TrialEndCheckWorker after success we could delete it as we are doing already.

Note that we would also need a sub type on top of this to not select fresh subscriptions in TrialEndCheckWorker.

One advantage is that we can use this for other types apart from trial based issues.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think its worth the complexity, want to keep it as simple as possible. We anyways typically have page sizes of around 100 or 1000 elsewhere in the code so don't think there will be orgs more than this on trial and we skip orgs for which trial not ended in the for loop.

Its a background job so may be not a big deal and not all checks are time based so next_check_time field will not be generic.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added one optimization where trial end check will only fetch processed on trial issues thus only orgs which are within a week of trial end date.

@pjain1 pjain1 self-assigned this Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants